



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class SystemStatusDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public SystemStatusDB()
        {
        }

        public SystemStatusDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<SystemStatus> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<SystemStatus> lstRet = new List<SystemStatus>();

            string strQuery = " select " + strTop  + " * from dbo.[SystemStatus]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    SystemStatus obj = new SystemStatus();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["StatusNameAR"] != DBNull.Value)
                    {
                        obj.StatusNameAR = (System.String)dr["StatusNameAR"];
                    }
                    else
                    {
                        obj.StatusNameAR = "";
                    } 
 if (dr["StatusNameEN"] != DBNull.Value)
                    {
                        obj.StatusNameEN = (System.String)dr["StatusNameEN"];
                    }
                    else
                    {
                        obj.StatusNameEN = "";
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<SystemStatus> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<SystemStatus> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , SystemStatus obj)
        {
            
            

                    DbParameter prmStatusNameAR = con.createParameter();
                    prmStatusNameAR.ParameterName = "@StatusNameAR";
                    prmStatusNameAR.DbType =DbType.String;
                    if (obj.StatusNameAR == null)
                    {
                        prmStatusNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusNameAR.Value = obj.StatusNameAR;
                    }
                

                    


                    DbParameter prmStatusNameEN = con.createParameter();
                    prmStatusNameEN.ParameterName = "@StatusNameEN";
                    prmStatusNameEN.DbType =DbType.String;
                    if (obj.StatusNameEN == null)
                    {
                        prmStatusNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusNameEN.Value = obj.StatusNameEN;
                    }
                

                    


           



            string strQuery = " insert into dbo.[SystemStatus] ([StatusNameAR],[StatusNameEN]) VALUES (@StatusNameAR,@StatusNameEN) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmStatusNameAR,prmStatusNameEN);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(SystemStatus obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, SystemStatus obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmStatusNameAR = con.createParameter();
                    prmStatusNameAR.ParameterName = "@StatusNameAR";
                    prmStatusNameAR.DbType =DbType.String;
                    if (obj.StatusNameAR == null)
                    {
                        prmStatusNameAR.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusNameAR.Value = obj.StatusNameAR;
                    }
                

                    


                    DbParameter prmStatusNameEN = con.createParameter();
                    prmStatusNameEN.ParameterName = "@StatusNameEN";
                    prmStatusNameEN.DbType =DbType.String;
                    if (obj.StatusNameEN == null)
                    {
                        prmStatusNameEN.Value = DBNull.Value;
                    }
                    else
                    {
                        prmStatusNameEN.Value = obj.StatusNameEN;
                    }
                

                    


           



            string strQuery = " update dbo.[SystemStatus] set [StatusNameAR]=@StatusNameAR,[StatusNameEN]=@StatusNameEN where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmStatusNameAR,prmStatusNameEN);

            

        }


        public void Update(SystemStatus obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, SystemStatus obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[SystemStatus]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( SystemStatus obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<SystemStatus> getSystemStatusByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<SystemStatus> lstRet = new List<SystemStatus>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<SystemStatus> getSystemStatusByID(System.Int64 ID)
                    {
                        List<SystemStatus> lstRet = new List<SystemStatus>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getSystemStatusByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<SystemStatus> getSystemStatusByStatusNameAR(ClassDataHandler con,System.String StatusNameAR)
                    {
                        List<SystemStatus> lstRet = new List<SystemStatus>();


                        DbParameter prmStatusNameAR = con.createParameter();
                        prmStatusNameAR.ParameterName = "@StatusNameAR";
                        prmStatusNameAR.DbType = DbType.String;
                        if (StatusNameAR == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmStatusNameAR.Value = StatusNameAR;
                        }


                        lstRet = Select(con, "" , " where [StatusNameAR]=@StatusNameAR ", prmStatusNameAR);



                        return lstRet;

                    }


                    public List<SystemStatus> getSystemStatusByStatusNameAR(System.String StatusNameAR)
                    {
                        List<SystemStatus> lstRet = new List<SystemStatus>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getSystemStatusByStatusNameAR(con, StatusNameAR);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<SystemStatus> getSystemStatusByStatusNameEN(ClassDataHandler con,System.String StatusNameEN)
                    {
                        List<SystemStatus> lstRet = new List<SystemStatus>();


                        DbParameter prmStatusNameEN = con.createParameter();
                        prmStatusNameEN.ParameterName = "@StatusNameEN";
                        prmStatusNameEN.DbType = DbType.String;
                        if (StatusNameEN == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmStatusNameEN.Value = StatusNameEN;
                        }


                        lstRet = Select(con, "" , " where [StatusNameEN]=@StatusNameEN ", prmStatusNameEN);



                        return lstRet;

                    }


                    public List<SystemStatus> getSystemStatusByStatusNameEN(System.String StatusNameEN)
                    {
                        List<SystemStatus> lstRet = new List<SystemStatus>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getSystemStatusByStatusNameEN(con, StatusNameEN);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<SystemStatus> Search(ClassDataHandler con, SystemStatus obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.StatusNameAR != "")
                    {
                        DbParameter prmStatusNameAR = con.createParameter();
                        prmStatusNameAR.ParameterName = "@StatusNameAR";
                        prmStatusNameAR.DbType =DbType.String;
                        if (obj.StatusNameAR == null)
                        {
                            prmStatusNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusNameAR.Value = obj.StatusNameAR;
                        }
                        strWhere += " [StatusNameAR]=@StatusNameAR AND ";
                        lstParameters.Add(prmStatusNameAR);
                     }



                    

                    if (obj.StatusNameEN != "")
                    {
                        DbParameter prmStatusNameEN = con.createParameter();
                        prmStatusNameEN.ParameterName = "@StatusNameEN";
                        prmStatusNameEN.DbType =DbType.String;
                        if (obj.StatusNameEN == null)
                        {
                            prmStatusNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusNameEN.Value = obj.StatusNameEN;
                        }
                        strWhere += " [StatusNameEN]=@StatusNameEN AND ";
                        lstParameters.Add(prmStatusNameEN);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<SystemStatus> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<SystemStatus> Search(SystemStatus obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<SystemStatus> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<SystemStatus> SearchOrLike(ClassDataHandler con, SystemStatus obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.StatusNameAR != "")
                    {
                        DbParameter prmStatusNameAR = con.createParameter();
                        prmStatusNameAR.ParameterName = "@StatusNameAR";
                        prmStatusNameAR.DbType =DbType.String;
                        if (obj.StatusNameAR == null)
                        {
                            prmStatusNameAR.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusNameAR.Value = obj.StatusNameAR;
                        }
                        strWhere += " [StatusNameAR] LIKE @StatusNameAR OR ";
                        lstParameters.Add(prmStatusNameAR);
                     }



                    

                    if (obj.StatusNameEN != "")
                    {
                        DbParameter prmStatusNameEN = con.createParameter();
                        prmStatusNameEN.ParameterName = "@StatusNameEN";
                        prmStatusNameEN.DbType =DbType.String;
                        if (obj.StatusNameEN == null)
                        {
                            prmStatusNameEN.Value = DBNull.Value;
                        }
                        else
                        {
                            prmStatusNameEN.Value = obj.StatusNameEN;
                        }
                        strWhere += " [StatusNameEN] LIKE @StatusNameEN OR ";
                        lstParameters.Add(prmStatusNameEN);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<SystemStatus> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<SystemStatus> SearchOrLike(SystemStatus obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<SystemStatus> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            